<template>
<el-autocomplete
  class="s"
  popper-class="my-autocomplete"
  v-model="state"
  :fetch-suggestions="querySearch"
  placeholder="请输入内容"
  @select="handleSelect">
  <i
    class="el-icon-search el-input__icon"
    slot="suffix"
    @click="handleIconClick">
  </i>
  <template slot-scope="{ item }">
    <div class="name">{{ item.value }}</div>
    <span class="addr">{{ item.address }}</span>
  </template>
</el-autocomplete>    
</template>

<script>
  export default {
    data() {
      return {
        restaurants: [],
        state:"",
        
      };
    },
    methods: {
      querySearch(queryString, cb) {
        var restaurants = this.restaurants;
        var results = queryString ? restaurants.filter(this.createFilter(queryString)) : restaurants;
        // 调用 callback 返回建议列表的数据
        cb(results);
      },
      createFilter(queryString) {
        return (restaurant) => {
          return (restaurant.value.toLowerCase().indexOf(queryString.toLowerCase()) === 0);
        };
      },
      loadAll() {
        return [
          { "value":"邓紫棋" },
          { "value":"张杰" },
        ];
      },
      handleSelect(item) {
        console.log(item);
      },
      handleIconClick(ev) {
        this.$store.commit("updateActive",'1')
          this.$store.commit("updatecurrent",`single`)
        this.$router.push(`search?keyword=${this.state}`).catch(()=>{})//导航到搜索页面     
      }
    },
    mounted() {
      this.restaurants = this.loadAll()
    }
  }
</script>
<style lang="scss">
.el-input__inner{
  background-color: #ff0000;
}
.my-autocomplete {
  
  li {
    line-height: normal;
    padding: 7px;
    .name {
      text-overflow: ellipsis;
      overflow: hidden;
    }
    .addr {
      font-size: 12px;
      color: #b4b4b4;
    }

    .highlighted .addr {
      color: #ddd;
    }
  }
}
</style>
